// this is the lock server
// the lock client has a similar interface

#ifndef lock_server_h
#define lock_server_h

#include "lock_protocol.h"
#include "lock_client.h"
#include "rpc.h"

#include <pthread.h>
#include <stdio.h>
#include <unistd.h>
#include <arpa/inet.h>
#include <sstream>
#include <string>
#include <map>

using namespace std;
class lock_server {

 protected:
  int nacquire;
  pthread_mutex_t mut;
  pthread_cond_t cond;

 public:
  /* A map that tells us if a lockid is currently locked or not. int is just a bool in this case */
  map<lock_protocol::lockid_t, int> locks;

  lock_server();
  ~lock_server();
  lock_protocol::status stat(int clt, lock_protocol::lockid_t lid, int &);
  lock_protocol::status acquire(int clt, lock_protocol::lockid_t lid, int &);
  lock_protocol::status release(int clt, lock_protocol::lockid_t lid, int &);
};

#endif 







